package com.example.recruitment_website.repository;

import com.example.recruitment_website.domain.Collection;
import com.example.recruitment_website.domain.Record;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;

public interface RecordRepository extends JpaRepository<Record,Integer> {
    @Query(value = "select id,user_id,article_id,article_title,img_url,date  from browse_record h where h.user_id = ?1 order by h.id desc",nativeQuery = true)
    List<Record> findByUser_id(int id);

    @Query(value = "select * from browse_record a where a.article_id = ?1 and a.user_id = ?2",nativeQuery = true)
    Record findByIdAndArticle_id(int id,int userId);

    @Transactional
    @Modifying
    @Query(value = "delete from browse_record where article_id = ?1 and user_id = ?2 ",nativeQuery = true)
    void deleteByArticle_idAndUser_id(int id, int userId);

}
